/**
 * 砍服务费详情对话框
 */
var CutServiceFee = {
    id: "cutservicefeeTable",//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
CutServiceFee.initColumn = function () {
    var columns = [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: '申请人', field: 'opuser_name', align: 'center', valign: 'middle', sortable: true},
        {title: '房源编号', field: 'house_id', align: 'center', valign: 'middle', sortable: true},
        {title: '房源服务费', field: 'servicefee', align: 'center', valign: 'middle', sortable: true},
        {title: '砍服务费金额', field: 'service_fee_str', align: 'center', valign: 'middle', sortable: true},
        {title: '处理人', field: 'user_name', align: 'center', valign: 'middle', sortable: true},
        {title: '成交时间', field: 'deal_time', align: 'center', valign: 'middle', sortable: true}];
    return columns;
};

/**
 * 检查是否选中
 */
CutServiceFee.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        CutServiceFee.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加
 */
CutServiceFee.openAdd = function () {
    var index = layer.open({
        type: 2,
        title: '添加',
        area: ['350px', '400px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/cutservicefee/cutservicefee_add'
    });
    this.layerIndex = index;
};

/**
 * 点击查看按钮时
 * @param userId 管理员id
 */
CutServiceFee.openCutServiceFee = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '砍服务费详情',
            area: ['900px', '400px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/cutservicefee/view/' + this.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除
 */
CutServiceFee.del = function () {
    if (this.check()) {

        var operation = function(){
            var ajax = new $ax(Feng.ctxPath + "/cutservicefee/delete", function () {
                Feng.success("删除成功!");
                CutServiceFee.table.refresh();
            }, function (data) {
                Feng.error("删除失败!" + data.responseJSON.message + "!");
            });
            ajax.set("id",CutServiceFee.seItem.id);
            ajax.start();
        };

        Feng.confirm("是否刪除?", operation);
    }
};

CutServiceFee.resetSearch = function () {
    $("#house_id").val("");
    $("#beginTime").val("");
    $("#endTime").val("");

    CutServiceFee.search();
}

CutServiceFee.search = function () {
    var queryData = {};

    queryData['house_id'] = $("#house_id").val();
    queryData['beginTime'] = $("#beginTime").val();
    queryData['endTime'] = $("#endTime").val();

    CutServiceFee.table.refresh({query: queryData});
}

$(function () {
    var defaultColunms = CutServiceFee.initColumn();
    var table = new BSTable("cutservicefeeTable", "/cutservicefee/list", defaultColunms);
    table.setPaginationType("client");
    CutServiceFee.table = table.init();
});
